//
//  HttpManager.m
//  BeanSproutEDU
//
//  Created by douya on 15/1/14.
//  Copyright (c) 2015年 douya. All rights reserved.
//

#import "HttpManager.h"
#import "AFNetworking.h"
#import "MainModel.h"
#import "VideoModel.h"
#define HOST @"http://admin.91douya.com/index.php/API/"
@implementation HttpManager
+(void)getMainInfoWithBlock:(void(^)(NSMutableArray *array,BOOL isSuccess))block
{
    
    NSString *urlString=[NSString stringWithFormat:@"%@Index/getLastest.html",HOST];//最新视频
    
    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
    AFHTTPRequestOperation *operation=[manager GET:urlString parameters:nil success:^(AFHTTPRequestOperation *operation,id responseObject){
        NSLog(@"请求成功！");
        MainModel *dModel=[MainModel parserMainInfoWithDictionary:responseObject];
        NSMutableArray *mutableArray=[NSMutableArray array];
        [mutableArray addObject:dModel];
        block(mutableArray,YES);
        
    }failure:^(AFHTTPRequestOperation *operation,NSError *error){
        NSLog(@"请求失败！");
        NSLog(@"%@",error.localizedDescription);
        block(nil,NO);
    }];
    
    [operation start];
    
}

+(void)getHotVideoWithBlock:(void(^)(NSMutableArray *array,BOOL isSuccess))block
{
    NSString *urlString=[NSString stringWithFormat:@"%@Index/getHot.html",HOST];
    
    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
    AFHTTPRequestOperation *operation=[manager GET:urlString parameters:nil success:^(AFHTTPRequestOperation *operation,id responseObject){
        NSLog(@"请求成功！");
        MainModel *dModel=[MainModel parserMainInfoWithDictionary:responseObject];
        NSMutableArray *mutableArray=[NSMutableArray array];
        [mutableArray addObject:dModel];
        block(mutableArray,YES);
        
    }failure:^(AFHTTPRequestOperation *operation,NSError *error){
        NSLog(@"请求失败！");
        NSLog(@"%@",error.localizedDescription);
        block(nil,NO);
    }];
    
    [operation start];

}
@end
